#include "downfallplayer.h"
#include"Defines.h"
#include"downbullet.h"
#include<QKeyEvent>

DownFallPlayer::DownFallPlayer() {

    //初始化加载飞机资源
    DownPlayer.load(HERO_PATH);
    //初始化飞机坐标
    p_X=(GAME_WIDTH-DownPlayer.width())/2;
    p_Y=GAME_HEIGHT-DownPlayer.height();
    //初始化飞机边框
    p_Rect.setWidth(DownPlayer.width());
    p_Rect.setHeight(DownPlayer.height());
    p_Rect.moveTo(p_X,p_Y);
    qDebug()<<"飞机";
}


void DownFallPlayer::setPosition(int x,int y){
    p_X=x;
    p_Y=y;
    p_Rect.moveTo(x,y);
}

void DownFallPlayer::shoot(){
    //累加时间间隔
    p_recorder++;
    //积累数字未带到发射子弹间隔
    if(p_recorder<BULLET_INTERVAL){
        return;
    }
    //达到发射间隔
    p_recorder=0;
    for(int i=0;i<BULLET_NUM;i++){
        if(p_bullets[i].b_Free){
            //空闲更改为非空闲
            p_bullets[i].b_Free=false;
            //设置子弹坐标
            //p_bullets[i].b_X=p_X+DownPlayer.width()/2-10;
            p_bullets[i].b_X=p_X+DownPlayer.width()/2-55;
            p_bullets[i].b_Y=p_Y-30;
            break;//避免全部射出
        }
    }

}
